package com.example.safeassistan.hiddendanger.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.safeassistan.R;
import com.example.safeassistan.hiddendanger.model.HiddenDangerMyModel;

import java.util.List;

public class HiddenDangerDepartmentAdapter extends BaseQuickAdapter<HiddenDangerMyModel.ResultDTO,BaseViewHolder> {
    public HiddenDangerDepartmentAdapter(@Nullable List<HiddenDangerMyModel.ResultDTO> data) {
        super(R.layout.item_hiddendanger_department_list, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HiddenDangerMyModel.ResultDTO item) {
        ImageView ivImg=helper.getView(R.id.ivImg);
        TextView tvDot=helper.getView(R.id.tvDot);
        TextView tvStatus1=helper.getView(R.id.tvStatus1);

        if (item.getHdangerImg()!=null) {
            String[] strs = item.getHdangerImg().split(",");
            Glide.with(mContext).load(strs[0].equals("") ? strs[1] : strs[0])
                    .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
                    .placeholder(R.mipmap.default_image).into(ivImg);
        }
        helper.setText(R.id.tvHiddendDangerName,item.getHdangerTitle()+"");
        helper.setText(R.id.tvOwer,item.getCreateBy()+"");
        helper.setText(R.id.tvDepartMent,item.getDepartName()+"");
        helper.setText(R.id.tvHiddendDangerType,item.getHiddenTypeName()+"");
        helper.setText(R.id.tvReform,item.getOverdue()==null?item.getAllottedTime():item.getOverdue());
        switch (item.getHdangerLevel()+""){
            case "3":
                helper.setText(R.id.tvHiddendDangerLevel,"一般");
                tvDot.setBackgroundResource(R.drawable.orange_circle);
                break;
            case "1":
                helper.setText(R.id.tvHiddendDangerLevel,"重大");
                tvDot.setBackgroundResource(R.drawable.red_circle);
                break;
        }

        switch (item.getDisposeStatus()+""){
            case "1":
                //待提交
                tvStatus1.setText("待提交");
                tvStatus1.setBackgroundResource(R.drawable.leftcorner_purple_bg);
                break;
            case "2":
                //待评审
                tvStatus1.setText("待评审");
                tvStatus1.setBackgroundResource(R.drawable.leftcorner_green_bg);
                break;
            case "3":
                //待整改
                if (item.getRectSubmit()==0){
                    tvStatus1.setText("待整改");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_blue_bg);
                }else {
                    tvStatus1.setText("重新整改");
                    tvStatus1.setBackgroundResource(R.drawable.leftcorner_blue_bg);
                }
                break;
            case "4":
                // 待验收
                tvStatus1.setText("待验收");
                tvStatus1.setBackgroundResource(R.drawable.leftcorner_red_bg);
                break;
            case "5":
                //已验收
                tvStatus1.setText("已验收");
                tvStatus1.setBackgroundResource(R.drawable.leftcorner_orange_bg);
                break;
            case "6":
                //已评审
                tvStatus1.setText("已撤销");
                tvStatus1.setBackgroundResource(R.drawable.leftcorner_gray_bg);
                break;
        }
    }
}